package com.dao;

import com.mapper.UserMapper;
import com.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MybatisDemo {
    public  void send() throws IOException {
//        //1.加载mybatis的核心配置文件，获取sqlsession（直接去官网复制）
//        String resource = "mybatis-config.xml";
//        InputStream inputStream = Resources.getResourceAsStream(resource);
//        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
////         2.获取sqlsession对象，用它执行sql
//        SqlSession sqlSession=sqlSessionFactory.openSession();
////          3.执行sql语句
////        List<User> users=sqlSession.selectList("test.selectAll");
////         3.获取UserMapper接口的代理对象
//        UserMapper userMapper=sqlSession.getMapper(UserMapper.class);
////        User users= userMapper.selectById(2);
//        List<User> users1=userMapper.selectAll();
//        for(int i=0;i<users1.size();i++)
//        {
//            System.out.println(users1.get(i).getUsername()+users1.get(i).getUsername());
//        }
//
////        4.释放资源
//        sqlSession.close();
    }
}
